// 流程常量

import { status } from "nprogress";

// 流程节点
export const NODE = {
  START: 0, //"开始"
  APPROVE: 1, //"审核"
  COPY: 2, //"抄送"
  CONDITION: 3, //"条件"
  EXCLUSIVE_GATEWANY: 4, //"排他网关"
  TRANSACT: 5, //"办理"
  TRIGGER: 6, //"触发器"
  END: 9, //"结束"
};

export const NODE_TYPE = {
  START_ENV: 0, //"开始"
  AUDIT: 1, //"审核"
  COPY: 2, //"抄送"
  CONDITION: 3, //"条件"
  GETAWAY: 4, //"排他网关"
  USER_TASK: 5, //"办理"
  TRIGGER: 6, //"触发器"
  END_ENV: 9, //"结束"
};

// 流程组件
/* export const WIDGET = {
  SINGLELINE_TEXT: 0, //"单行文本"
  MULTILINE_TEXT: 1, //"多行文本"
  DESCRIBE: 2, //"提示文字"
  NUMBER: 3, //"数字"
  MONEY: 4, //"金额"
  SINGLE_CHOICE: 5, //"单选"
  MULTI_CHOICE: 6, //"多选"
  DATE: 7, //"日期"
  DATE_RANGE: 8, //"日期区间"
  DETAIL: 9, //"明细"
  PICTURE: 10, //"图片"
  ATTACHMENT: 11, //"附件"
  DEPARTMENT: 12, //"部门"
  EMPLOYEE: 13, //"员工"
  ADDRESS: 14, //"地址"
  FLOW_INST: 15, //"关联审批"
  AREA: 16, //"省市区"
}; */

export const WIDGET = {
  SINGLELINE_TEXT: "INPUT", //"单行文本"
  MULTILINE_TEXT: "TEXAREA", //"多行文本"
  DESCRIBE: "DESC", //"提示文字"
  NUMBER: "NUMBER", //"数字"
  MONEY: "MONEY", //"金额"
  SINGLE_CHOICE: "SINGLE_CHOICE", //"单选"
  MULTI_CHOICE: "MULTI_CHOICE", //"多选"
  DATE: "DATE", //"日期"
  DATE_RANGE: "DATE_RANGE", //"日期区间"
  DETAIL: "SUBFORM", //"明细"
  PICTURE: "UPLOAD-IMAGE", //"图片"
  ATTACHMENT: "UPLOAD-FILE", //"附件"
  DEPARTMENT: "ORG", //"部门"
  EMPLOYEE: "PERSON", //"员工"
  ROLE: "ROLE", //"角色"
  ADDRESS: "ADDRESS", //"地址"
  FLOW_INST: "FLOW_INST", //"关联审批"
  AREA: "AREA", //"省市区"
};

export const EX = {
  "search-select": "SINGLE_CHOICE",
  radio: "SINGLE_CHOICE",
  checkbox: "MULTI_CHOICE",
  "capital-number": "MONEY",
};

// 流程指令
export const CMD = {
  START: 0, // "发起"
  AUTO_APPROVED: 1, // "自动通过"
  AUTO_REJECTED: 2, // "自动拒绝"
  REJECTED: 3, // "拒绝"
  APPROVED: 4, // "通过"
  CANCELED: 5, // "撤销"
  ASSIGN: 6, // "转交"
  BACK: 7, // "回退"
  ADD_SIGN: 8, // "加签"
  DEL_SIGN: 9, // "减签"
  ADD_BEFORE_SIGN: 10, // "前加签"
  ADD_AFTER_SIGN: 11, // "后加签"
  COPY: 12, // "抄送"
  FORWARD: 13, // "转发"
  COMMENT: 14, // "评论"
  TRANSACT: 15, // "办理"
  SUBMIT: 16, // "提交"
};

// 流程状态
export const STATUS = {
  UNDERWAY: 0, //"审批中"
  APPROVED: 1, //"已通过"
  REJECTED: 2, //"不通过"
  CANCELLED: 3, //"已撤销"
};

export const STATUS_LIST = [
  {
    value: "RUNNING",
    name: "正在运行",
  },
  {
    value: "FINISH",
    name: "已结束",
  },
  {
    value: "STOP",
    name: "已停止",
  },
  {
    value: "SUSPEND",
    name: "已中断",
  },
  {
    value: "REVOKE",
    name: "已撤回",
  },
  {
    value: "PROCESS",
    name: "已发起",
  },
];

export const TASK_STATUS = [
  {
    value: "",
    name: "审批中",
  },
  {
    value: "1",
    name: "已通过",
  },
  {
    value: "0",
    name: "不通过",
  },
  {
    value: "REVOKE",
    name: "已撤回",
  },
];

export const INSTANCE_STATUS = {
  TEMP: {
    text: "已保存",
    status: "normal",
    color: "gray",
  },
  RUNNING: {
    text: "正在运行",
    status: "success",
    color: "green",
  },
  FINISH: {
    text: "已结束",
    status: "normal",
    color: "gray",
  },
  STOP: {
    text: "已停止",
    status: "danger",
    color: "red",
  },
  SUSPEND: {
    text: "已中断",
    status: "warning",
    color: "orange",
  },
  REVOKE: {
    text: "已撤回",
    status: "processing",
    color: "blue",
  },
  ARCHIVE: {
    text: "已归档",
    status: "normal",
    color: "gray",
  },
};

// 流程执行人
export const ASSIGNEE = {
  SELF: 0, // "发起人本人"
  SUPERIOR: 1, // "上级"
  DEPARTMENT_LEADER: 2, // "部门负责人"
  ROLE: 3, // "角色"
  ASSIGNEE: 4, // "指定成员"
  MULTISTEP_LEADER: 5, // "连续多级上级"
  MULTISTEP_DEPARTMENT_LEADER: 6, // "连续多级部门负责人"
  INITIATOR_CHOICE: 7, // "发起人自选"
};

// 节点加签类型
export const NODE_SIGN = {
  NONE: 0, //"无"
  ADD_BEFORE_SIGN: 1, //"前加签"
  ADD_AFTER_SIGN: 2, //"后加签"
  ADD_SIGN: 3, //"加签"
  DEL_SIGN: 4, //"减签"
};

// 审批人类型
// 0：发起人本人 1：上级 2：部门负责人 3：角色 4：指定成员 5：连续多级上级  6：连续多部门负责人 7：发起人自选
export const ASSIGNEE_TYPE = {
  0: "SELF",
  1: "UP",
  2: "MANAGER",
  3: "ROLE",
  4: "USER",
  5: "MULTISTEP_LEADER",
  6: "MULTISTEP_DEPARTMENT_LEADER",
  7: "UNDETERMINED",
  8: "FORM_USER",
  9: "FORM_ORG",
  10: "ORG", // "部门"
  11: "DISABLED", // "全员不可提交"
  12: "ALL", // "全部"
};

// 审批方式
export const MULTI_TYPE = {
  1: "AND",
  2: "OR",
  3: "ORDER",
};

// 发起人和审批人是同一人
export const SAME_TYPE = {
  0: "AUDIT",
  1: "SKIP",
  2: "UP",
  3: "MANAGER",
};

// 审批人为空时
export const NO_AUDITOR_TYPE = {
  0: "SKIP",
  1: "USER",
  2: "ADMIN",
};

// 任务状态过滤条件
export const filterStatus = (inst) => {
  if (
    (inst.instanceStatus &&
      inst.instanceStatus != "FINISH" &&
      inst.instanceStatus != "REVOKE") ||
    (inst.flowInstance &&
      inst.flowInstance.instanceStatus != "FINISH" &&
      inst.flowInstance.instanceStatus != "REVOKE")
  ) {
    console.log(0);
    return STATUS.UNDERWAY;
  } else if (
    inst.operateFlag == TASK_STATUS[1].value ||
    (inst.flowInstance && inst.flowInstance.auditStatus) ==
      TASK_STATUS[1].value ||
    inst.auditStatus == TASK_STATUS[1].value
  ) {
    console.log(1);
    return STATUS.APPROVED;
  } else if (
    inst.operateFlag == TASK_STATUS[2].value ||
    (inst.flowInstance && inst.flowInstance.auditStatus) ==
      TASK_STATUS[2].value ||
    inst.auditStatus == TASK_STATUS[2].value
  ) {
    console.log(2);
    return STATUS.REJECTED;
  } else if (
    inst.instanceStatus == TASK_STATUS[3].value ||
    (inst.flowInstance && inst.flowInstance.instanceStatus) ==
      TASK_STATUS[3].value
  ) {
    console.log(3);
    return STATUS.CANCELLED;
  }
};
